package com.hyt.it.ogt.kq.main.controller.bm;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.it.ogt.kq.common.bm.utils.Constant;
import com.hyt.it.ogt.kq.main.controller.base.BaseController;
import com.hyt.it.ogt.kq.service.bm.model.vo.InvoiceSettingVo;
import com.hyt.it.ogt.kq.service.bm.service.IInvoiceSettingService;
import com.hyt.log.annotation.Log;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liteng
 * @since 2020-09-01
 */
@RestController
@Api(tags = "16.发票设置", value = "发票设置")
@ApiSort(value = 16)
@RequestMapping("/bm/invoice-setting")
public class InvoiceSettingController extends BaseController {

    @Autowired
    IInvoiceSettingService iInvoiceSettingService;


    @ApiOperationSort(value = 1)
    @Log(module = "发票管理", business = "发票设置")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Object save(@RequestBody InvoiceSettingVo invoiceSettingVo) {
        try {
            iInvoiceSettingService.saveInvoiceSetting(invoiceSettingVo);
            return ApiResponse.builder()
                    .code(Constant.RESPONSE_CODE_SUCCESS)
                    .build();
        } catch(Exception e){
            if("14076".equals(e.getMessage())){
                return ApiResponse.builder()
                        .code(Constant.RESPONSE_CODE_31010116)
                        .build();
            }
            return ApiResponse.builder()
                    .code(Constant.RESPONSE_CODE_31010116)
                    .build();
        }
    }

    @ApiOperation(value = "16.1.2 查询发票设置", notes = "20000:成功", response = InvoiceSettingVo.class)
    @ApiOperationSort(value = 2)
    @RequestMapping(value = "/queryInvoice", method = RequestMethod.GET)
    public Object queryInvoice(String invoiceType) {
        try {
            InvoiceSettingVo vo = iInvoiceSettingService.queryInvoice(getOfficeId(),invoiceType);
            return ApiResponse.builder()
                    .code(Constant.RESPONSE_CODE_SUCCESS)
                    .data(vo)
                    .build();
        } catch(Exception e){
            return ApiResponse.builder()
                    .code(Constant.RESPONSE_CODE_31010117)
                    .build();
        }

    }
}
